from sqlalchemy import Column, Integer, String, CHAR, DateTime, Float, desc, text, DECIMAL
from app.models.base import db, Base


class SentenceDetail(Base):
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(30), nullable=False)
    sentence_index = Column(CHAR(8), nullable=False)
    original_content = Column(String(150), nullable=False)
    similar_content = Column(String(1000), default='佚名')
    rate = Column(DECIMAL(5, 2), default=0)
    source = Column(String(250), default=0)
    title = Column(String(80), default=0)
    author = Column(String(50), default='')
    url = Column(String(1000), default='')

    def keys(self):
        return ['id', 'order_number', 'sentence_index', 'original_content', 'rate', 'source',
                'title', 'author', 'url', 'show_rate', 'show_similar_content']

    @property
    def show_rate(self):
        return str(self.rate * 100) + '%'

    @property
    def show_similar_content(self):
        return self.similar_content.replace('<em>', '<em style="color: red;font-style:normal">')
